# Importing Data
ISRAEL<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "D1:D264")

# Checking the Imported Data
View(ISRAEL)
# Creating Time Series Data
ISRAEL_ts <- ts(ISRAEL, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
ISRAEL_ts
sum(is.na(ISRAEL_ts))
library(forecast)
ISRAEL_ts <- tsclean(ISRAEL_ts)
ISRAEL_ts

# Identification: Plotting the Time Series Data
plot(ISRAEL_ts)

# Estimating the appropriate model
ISRAEL_ts_model <- auto.arima(ISRAEL_ts)
ISRAEL_ts_model

# Forecasting
options(max.print=1000000)
ISRAEL_ts_forecast <- forecast (ISRAEL_ts_model, level=c(95), h=264)
plot(ISRAEL_ts_forecast)
ISRAEL_ts_forecast             

# Exporting
write.table(ISRAEL_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/ISRAEL_TSA.csv", sep=",")
